<?php

class Api_Model_GetHanghoa extends Zend_Db_Table_Abstract
{
    protected $_name="dmhanghoadv";
    protected $_primary="Id";
    
    var $Id, $Ten,$Idnhomhhdv,$Iddonvitinh,$GiaMua,$GiaBan,$MaVach,$DuongDanAnh,$TrangThai,$NgayTao, $DienGiai;
    
    public function __construct() {
    	$this->_name = Zend_Registry::get('tablePrefix') . $this->_name;
    	    
    	parent::__construct();
    }
    
	
	public function GetAll() {
	    
	    $query = $this->_db->select()
	    						->from(array('T1'=>'os_dmhanghoadv'))
	    						->joinLeft(array('T2' => 'os_dmdonvitinh'), 'T1.Iddonvitinh = T2.Id', array('T2.Ten as DVT'))
	    						->joinLeft(array('T3' => 'os_dmnhomhhdv'), 'T1.Idnhomhhdv = T3.Id', array('T3.Ten as NhomHHDV'));
	    
	    
	    $stmt = $this->_db->query($query);
	    
	   return $result = $stmt->fetchAll();
	    
	    var_dump($result);
    }
    public function GetById()
    {
    	return $this->fetchAll("Id='$this->Id'")->toArray();
    }
    
    public function GetHangHoaTheoNhom($IdNhomhanghoa) {
    
    	$query = $this->_db->select()
    	->from(array('T1'=>'os_dmhanghoadv'))
    	->joinLeft(array('T2' => 'os_dmnhomhhdv'), 'T1.Idnhomhhdv = T2.Id', array('T2.Ten as Nhom'))
    	->where ("T1.Idnhomhhdv='". $IdNhomhanghoa . "'");
    	$stmt = $this->_db->query($query);
    		
    	return $result = $stmt->fetchAll();
    		
    	var_dump($result);
    }
	
}

